using System;
using System.Collections.Generic;
using System.Text;
using org.qsoft.rpcfx.bean;
using org.qsoft.rpcfx.common;
using System.Collections;
using System.Reflection;
using org.qsoft.rpcfx.util;

namespace nrpcfx.org.qsoft.rpcfx.bean.json
{
    public class QJsonWriter : AbstractObjectWriter
    {

        private StringBuilder buffer = new StringBuilder();

        public override void writeNode(object obj, string name)
        {
            if (obj == null) return;

            buffer.Append(name);
            buffer.Append(":");
            bool flag = TypeUtil.isNoQuot(obj.GetType().FullName);
            string val = obj.ToString();
            if (!flag)
                val = "'" + val + "'";
            buffer.Append(val);
            buffer.Append(",");
            buffer.Append("\r\n");

            
        }

        public override void writeStart(string name, string type)
        {
            buffer.Append(name);
            buffer.Append(":");
            buffer.Append("{");
            buffer.Append("\r\n");
        }

        public override void writeEnd()
        {
            buffer.Append("}");
            buffer.Append("\r\n");
        }

        public override string Serialize(object target)
        {
            this.buffer = new StringBuilder(1024);
            write(target, "root");
            return this.buffer.ToString();
        }
    }



}

